import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { SubjectService } from './subject.service';
import { CreateSubjectDto } from './dto/create-subject.dto';
import { UpdateSubjectDto } from './dto/update-subject.dto';
import { Result } from '../common/dto/common.result';
import { PageSubjectDto } from './dto/page-subject.dto';

/**
 * 科目控制器
 */
@Controller('subject')
export class SubjectController {
  constructor(private readonly subjectService: SubjectService) { }

  @Post('/save')
  async create(@Body() createSubjectDto: CreateSubjectDto) {
    await this.subjectService.create(createSubjectDto);
    return Result.success();
  }

  @Get('/list')
  async findAll() {
    return Result.successData(await this.subjectService.findAll());
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.subjectService.findOne(id))
  }

  @Patch('/info/:id')
  async update(@Param('id') id: number, @Body() updateSubjectDto: UpdateSubjectDto) {
    this.subjectService.update(id, updateSubjectDto);
    return Result.success();
  }

  @Delete('/info/:id')
  async remove(@Param('id') id: number) {
    await this.subjectService.remove(id);
    return Result.success();
  }

  @Patch('/info/status')
  async changeStatus(@Body() updateSubjectDto: UpdateSubjectDto) {
    await this.subjectService.changeStatus(updateSubjectDto.id, updateSubjectDto.status);
    return Result.success();
  }

  @Get("/list/page")
  async page(pageSubjectDto: PageSubjectDto) {
    return Result.successData(await this.subjectService.page(pageSubjectDto));
  }
}
